package panel.viewSpots
{
	import assists.HtmlText;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import com.greensock.TweenLite;
	
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import struct.Scenic;
	import struct.TourElementBase;
	
	public class AroundGroup extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader
		private var _label:TextField = new TextField();
		private var _icon:Bitmap;
		private var _itemContainer:Sprite = new Sprite();
		private var _openDetail:Function;
		public function AroundGroup(stage:Stage,loader:ResourceLoader)
		{
			_stage = stage;
			_loader = loader;
			init();
		}
		
		private function init():void
		{
			_icon = new _loader.uiManager.aroundPng();
			
			_label.mouseEnabled = false;
			_label.autoSize = "left";
			
			TextFieldUtils.setHtmlText(_label,HtmlText.formatSizeColor("周边：",0xffffff,22));
			_icon.width = _icon.height = _stage.stageWidth * 0.05;
			_label.x = _icon.x + _stage.stageWidth * 0.02 + _icon.width;
			_itemContainer.y = _icon.y + _icon.height + _stage.stageHeight * 0.02;
			
			this.addChild(_icon);
			this.addChild(_label);
			this.addChild(_itemContainer);
			
		}
		
		public function show(dataList:Array,allDataList:Array):void
		{
			if(dataList.length == 1 || allDataList.length == 0)return;
			var wid:int = _stage.stageWidth * 0.2;
			for(var i:int=0;i<dataList.length;i++)
			{
				var aroundItem:AroundItem = new AroundItem(_loader,wid);
				aroundItem.addEventListener(MouseEvent.CLICK,clickHandler);
				aroundItem.show(seedData(allDataList,dataList[i]));
				aroundItem.x = (aroundItem.width + 20) * i + 20;
				_itemContainer.addChild(aroundItem);
			}
			
		}
		
		protected function clickHandler(event:MouseEvent):void
		{
		var item:AroundItem = event.target as AroundItem;
			_openDetail(item.data);
		}
		
		public function openDetail(value:Function):void
		{
			_openDetail = value;
		}
		
		private function seedData(list:Array,index:uint):TourElementBase
		{
			for(var i:int=0;i<list.length;i++)
			{
				if(index == list[i].id)
				{
					return list[i];
				}
			}
			return null;
		}
		
	}
}